WPF Diagrams includes built-in visual styles for the predefined DiagramConnection class, which can be extended by setting the LineType and configuring a suitable LineTypeLayout resource.

You will usually need to customise connection visuals at the Foundation level only you are creating your own diagram type and need to implement your own connection data model or connectivity logic. Even then, most requirements can be met by extending DiagramConnection and adding suitable connectivity logic to node classes, rather than implementing a whole new connection type.

However if you do need to rip and replace connection visuals then you can do so by defining a Style and hooking up that style to the DiagramSurface through the Formatter property.

Creating a Custom Connection Style

Most customisation of connection appearance can be carried out by creating one or more Styles in your XAML representing the appearance you require. You must then create a StyleSelector which references these styles. In most cases, you will create only one Style, and will use a FixedStyleSelector to select it. (The use of a selector is to provide additional flexibility for special scenarios.)

Your style must have a TargetType of DiagramConnectionElement, and will typically set the Template property to replace the control template. DiagramConnectionElement control templates are often relatively complex because a connection has lots of parts. A full example is shown in the CustomStyle sample. Your ControlTemplate will typically define the following elements.

Selecting the New Style

Once you have created this style, you must create a StyleSelector to select it. If you are using the same style for all connections, as is typical, you can use the FixedStyleSelector for this.

Finally you must create a DiagramFormatter instance which references your StyleSelector.

For a worked example, please refer to the CustomStyle sample.